package org.redpig.mimall.exception;

import org.redpig.mimall.pojo.User;
import org.redpig.mimall.vo.ResponseVo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import static org.redpig.mimall.enums.ResponseEnum.ERROR;
import static org.redpig.mimall.enums.ResponseEnum.NEED_LOGIN;

@ControllerAdvice
public class RuntimeExceptionHandler {

    @ResponseBody
//    @ResponseStatus(HttpStatus.FORBIDDEN)
    @ExceptionHandler(RuntimeException.class)
    public ResponseVo<User> handle(RuntimeException runtimeException) {
        return ResponseVo.error(ERROR, runtimeException.getMessage());
    }

    @ResponseBody
    @ExceptionHandler(UserLoginException.class)
    public ResponseVo<User> handle() {
        return ResponseVo.error(NEED_LOGIN);
    }
}
